<?php
/**
 * This file is part of webman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

use app\common\ApiStatus;
use Webman\Route;
use app\middleware\ApiAuthCheck;

//use app\middleware\Ajax;
//use app\middleware\CheckIndex;

//************************ ↓↓ WEB 接口 ↓↓ ************************

//Route::get('/web/api/agreement/{id:\d+}', [app\web\controller\Agreement::class, 'api']);

//************************ ↑↑ WEB 接口 ↑↑ ************************

//************************ ↓↓ API 接口 ↓↓ ************************
// API接口已启用自动路由功能，如果需要特别配置，可以单独控制
Route::group('/api', function () {
    Route::any('/aes_test', function ($request) {
        $key  = \app\service\AesService::instance()->setkey('T3lUf3t3pdHzSx8U')->encrypt('/v1/auth/ossStsToken' . time());
        $data = [
            'key' => urldecode($key),
        ];
        return json($data);
    });
});
Route::group('/h5', function () {
    Route::get('/payCallback/alipay', [app\h5\v1\controller\PayCallback::class, 'alipay']);
    Route::any('/payCallback/wechat/', [app\h5\v1\controller\PayCallback::class, 'wechat']);
    Route::any('/payCallback/apple', [app\h5\v1\controller\PayCallback::class, 'apple']);
});
//************************ ↑↑ API 接口 ↑↑ ************************

Route::fallback(function ($callback) {
    return json(['code' => ApiStatus::API_NOT_FOUND->value, 'msg' => ApiStatus::from(ApiStatus::API_NOT_FOUND->value)->getStatus(), 'request_id' => md5(uniqid(mt_rand(), true))]);
});


Route::get('/robots.txt', function () {
    $content = "User-agent: *";
//    if (ENVIRONMENT == 'DEV') $content .= PHP_EOL . "Disallow: /";
    $headers = ['Content-Type' => 'text/plain'];
    return response($content, 200, $headers);
});
